package com.sip;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.sip.db.entity.ChannelEntity;
import com.sip.db.entity.DeviceEntity;
import com.sip.db.service.ChannelService;
import com.sip.db.service.DeviceService;

@RestController
@RequestMapping("/api")
public class ApiController {
	@Autowired
	DeviceService deviceService;
	@Autowired
	SipLayer sipLayer;
	@Autowired
	ChannelService channelService;
	@RequestMapping("/list/device")
	public ResponseEntity<List<DeviceEntity>> deviceList(){
		List<DeviceEntity> list = deviceService.listAll(new DeviceEntity());
		return new ResponseEntity<List<DeviceEntity>>(list,HttpStatus.OK);
	}
	@RequestMapping("/list/channel/{deviceId}")
	public ResponseEntity<List<ChannelEntity>> channelList(@PathVariable String deviceId){
		List<ChannelEntity> list = channelService.listAll(new ChannelEntity());
		return new ResponseEntity<List<ChannelEntity>>(list,HttpStatus.OK);
	}
	@RequestMapping("/ptz/{deviceId}_{channelId}")
	public ResponseEntity<String> ptz(@PathVariable String deviceId,@PathVariable String channelId,int leftRight, int upDown, int inOut, int moveSpeed, int zoomSpeed){
		sipLayer.requestPtz(deviceId, channelId, leftRight, upDown, inOut, moveSpeed, zoomSpeed);
		return new ResponseEntity<>(HttpStatus.OK);
	}
	@RequestMapping("/live/{deviceId}_{channelId}")
	public ResponseEntity<String> live(@PathVariable String deviceId,@PathVariable String channelId){
		sipLayer.requestInvite(deviceId, channelId);
		return new ResponseEntity<>(HttpStatus.OK);
	}
	@RequestMapping("/replay/list/{deviceId}_{channelId}")
	public ResponseEntity<String> replayList(@PathVariable String deviceId,@PathVariable String channelId,String startTime,String endTime){
		sipLayer.requestReplayList(deviceId, channelId, startTime, endTime);
		return new ResponseEntity<>(HttpStatus.OK);
	}
	@RequestMapping("/replay/{deviceId}_{channelId}")
	public ResponseEntity<String> replay(@PathVariable String deviceId,@PathVariable String channelId,String startTime,String endTime){
		sipLayer.requestReplay(deviceId, channelId, startTime, endTime);
		return new ResponseEntity<>(HttpStatus.OK);
	}
	@RequestMapping("/bye/{deviceId}_{channelId}")
	public ResponseEntity<String> bye(@PathVariable String deviceId,@PathVariable String channelId,String method){
		sipLayer.requestBye(deviceId, channelId, method);
		return new ResponseEntity<>(HttpStatus.OK);
	}
}
